import CommonBaseModel, { moneyTransform } from '#common/base_model'
import { belongsTo, column } from '@adonisjs/lucid/orm'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
import Dict from '#models/dict'

export default class Goods extends CommonBaseModel {
  /** 商品类别 */
  @column()
  declare fkCategoryId: number

  /** 供应商 */
  @column()
  declare fkSupplierId: number | null

  /** 仓库外键 */
  @column()
  declare fkWarehouseId: number

  /** 购买单位外键 */
  @column()
  declare fkBuyUnitId: number

  /** 置换数量 */
  @column()
  declare buyUnitNumber: number

  /** 购买单位价格 */
  @column()
  declare buyUnitPrice: number

  /** 标准单位 */
  @column()
  declare fkStandardUnitId: number

  /** 商品名称 */
  @column()
  declare name: string

  /** 规格 */
  @column()
  declare spec: string

  /** 位置 */
  @column()
  declare place: string

  /** 正常价格 */
  @column(moneyTransform)
  declare normalPrice: number

  /** 条形码 */
  @column()
  declare barCode: string

  /** 状态 */
  @column()
  declare status: number

  /** 备注 */
  @column()
  declare memo: string

  @belongsTo(() => Dict, { foreignKey: 'fkCategoryId' })
  declare category: BelongsTo<typeof Dict>
}
